import type { CrmSalesOrder, CrmSalesDetail } from "@/pages/wms/saleOrder/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //订单编码
  code?: string;
  //订单类型
  type?: string;
  //订单日期
  orderDate?: Date;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: CrmSalesOrder[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/wms/saleOrder/pageList",
    data
});
const getInfo = (id: React.Key): Promise<CrmSalesOrder> =>
  apiClient.get({
    url: `/wms/saleOrder/${id}`
});

const add = (data: CrmSalesOrder): Promise<CrmSalesOrder> =>
  apiClient.post({
    url: "/wms/saleOrder",
    data
});

const update = (data: CrmSalesOrder): Promise<CrmSalesOrder> =>
  apiClient.put({
    url: "/wms/saleOrder",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/wms/saleOrder",
    params: {
    ids: ids.join(",")
  }
});
const getsaleDetails = (id: React.Key): Promise<CrmSalesDetail[]> =>
  apiClient.post({
    url: "/wms/saleDetail/list",
    data: {
      OrderId: id
    }
  });

export const crmSalesOrderService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getsaleDetails,
};

export default crmSalesOrderService;